<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>抢筹</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">				
			//p {margin:5px}
			//ul {margin:1px}			
			//h4 {margin:1px}	
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}			
		</style>		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script>		   
			window.onload = function() {						
			getSource("0","1");
			changeStyle();
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource("0",px);					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","10:00")									
				},
				60000);
			})
			
			function changeStyle() {
				var obj1 = document.getElementById("towrite");				
				obj1.style.left= "0px"; 				
				obj1.style.width= "480px";	
				obj1.style.height= "620px";		
				obj1.style.fontSize="12px";				  			 
			}	
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function getLocalTime(nS) {			          
			return new Date(parseInt(nS) * 1000).Format("hh:mm:ss")}						
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};
			
			function changeCss(obj,id){				
				var alist = document.getElementById(id).getElementsByTagName("a");					
				for(var i = 0; i < alist.length; i++){				
					if(alist[i] == undefined){
						break;
					}
					alist[i].style.color = "#d2d2d3"; //给所有a标签赋原色
				}
				obj.style.color = "#00FFFF"; //令当前标签高亮				
			}
			
			function createXmlHttp() {
				if (window.XMLHttpRequest) {
				xmlHttp = new XMLHttpRequest();
				} else {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}				
			}
			
			var t = "";
			var px = "1";
			var gl = "";  //高亮
			function getSource(ss,pp) {
				t = ss;
				px = pp;
				var zp = "<a href='javascript:void(0)' id='bt1' onclick='getSource(" + "\"0\"" + "," + px + ")'>" + "早盘抢筹" + "</a>";
				var wp = "<a href='javascript:void(0)' id='bt2' onclick='getSource(" + "\"1\"" + "," + px + ")'>" + "尾盘抢筹" + "</a>";	
				var p1 = "<a href='javascript:void(0)' id='px1' onclick='getSource(" + t + "," + "\"1\"" + ")'>" + "按抢筹委托金额排序" + "</a>";
				var p2 = "<a href='javascript:void(0)' id='px2' onclick='getSource(" + t + "," + "\"2\"" + ")'>" + "按抢筹成交金额排序" + "</a>";					
				var p30 = "<a href='javascript:void(0)' id='px3' onclick='getSource(" + t + "," + "\"3\"" + ")'>" + "按开盘金额排序" + "</a>";
				var p31 = "<a href='javascript:void(0)' id='px3' onclick='getSource(" + t + "," + "\"3\"" + ")'>" + "按收盘金额排序" + "</a>";
				if(t == "0")
					{							
						p3 = p30;
					}
				else if(t == "1")
					{							
						p3 = p31;
					}				
				var p4 = "<a href='javascript:void(0)' id='px4' onclick='getSource(" + t + "," + "\"4\"" + ")'>" + "按抢筹幅度排序" + "</a>";
				div1 = document.getElementById('towrite');
				div1.innerHTML = "<h4>" + zp + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + wp + "</h4><p>" + p1 + p2 + p3 + p4 + "</p>";
				
				if(t == "0"){
				aObj = document.getElementById('bt1');				
				aObj.style.color = "#FFA07A";
				}
				
				if(t == "1"){
				aObj = document.getElementById('bt2');				
				aObj.style.color = "#FFA07A"; 
				}
				
				aObj1 = document.getElementById('px' + pp);
				gl = aObj1.innerText;
				gl = gl.replace("按","").replace("排序","");				
				aObj1.innerText = aObj1.innerText + "↓";
				aObj1.style.color = "#FFA07A"; 
				
				var url = "http://excalc.icfqs.com:7616/TQLEX?Entry=HQServ.hq_nlp"; 	                			
				createXmlHttp();
				//早盘				
				var array1 = '[{"funcId":20,"offset":0,"count":50,"sort":' + px + ',"period":0,"Token":"6679f5cadca97d68245a086793fc1bfc0a50b487487c812f","modname":"JJQC"}]';
				array1 = eval(array1);
				
				//尾盘				
				var array2 = '[{"funcId":20,"offset":0,"count":50,"sort":' + px + ',"period":1,"Token":"6679f5cadca97d68245a086793fc1bfc0a50b487487c812f","modname":"JJQC"}]';
				array2 = eval(array2);				
				xmlHttp.onreadystatechange = writeSource;
				xmlHttp.open("POST", url, true);				
				xmlHttp.setRequestHeader("User-Agent","TdxW");
				
				if(ss == "0")
					{	
						xmlHttp.send(JSON.stringify(array1)) ;						
					}
				if(ss == "1")
					{											
						xmlHttp.send(JSON.stringify(array2)) ; 						
					}						
			}
								
			var dms = "";
			function writeSource() { 			
				if (xmlHttp.readyState == 4) { 	
					var data = xmlHttp.responseText						
					//document.write(data);					
					var html = "";												
					if(data.indexOf("\"datas\": []") == -1)
					{											
						data = data.replace(/ /g,"").match(/\"datas\":\[(\S*)\]\}/)[1];	
						data = data.replace(/(\[).*?(?=\])/g,function(word){ 
						str = word.match(/\[(\S*)/)[1]; 
						return '{"code":' + str.split(',')[0] + 
						',"name":' + str.split(',')[1] + 
						',"kpje":' + str.split(',')[4] + 
						',"fd":' + str.split(',')[5] +
						',"wtje":' + str.split(',')[6] +
						',"cjje":' + str.split(',')[7];
						});
						data = "{\"data\":[" + data.replace(/\],\{/g,"},{").replace(/\]/g,"}]}");
						//document.write(data);
						//开盘金额				
						data = data.replace(/(\"kpje\":).*?(?=,)/g, function(word){ 						
						str = word.match(/\"kpje\":(\S*)/)[1];
							if(keepTwoDecimal(str/100000000) >= 1)
							{
								return '\"kpje\":\"' + keepTwoDecimal(str/100000000) + '亿\"';
							}
							else
							{
								return '\"kpje\":\"' + Math.round(str/10000) + '万\"';
							}
													
						}); 
						
						//抢筹委托金额				
						data = data.replace(/(\"wtje\":).*?(?=,)/g, function(word){ 						
						str = word.match(/\"wtje\":(\S*)/)[1];
							if(keepTwoDecimal(str/100000000) >= 1)
							{
								return '\"wtje\":\"' + keepTwoDecimal(str/100000000) + '亿\"';
							}
							else
							{
								return '\"wtje\":\"' + Math.round(str/10000) + '万\"';
							}
													
						});
						
						//抢筹成交金额				
						data = data.replace(/(\"cjje\":).*?(?=})/g, function(word){ 						
						str = word.match(/\"cjje\":(\S*)/)[1];
							if(keepTwoDecimal(str/100000000) >= 1)
							{
								return '\"cjje\":\"' + keepTwoDecimal(str/100000000) + '亿\"';
							}
							else
							{
								return '\"cjje\":\"' + Math.round(str/10000) + '万\"';
							}
													
						});

						//抢筹幅度				
						data = data.replace(/(\"fd\":).*?(?=,)/g, function(word){ 				
							str = word.match(/\"fd\":(\S*)/)[1]; 					
							return '\"fd\":"' + keepTwoDecimal(str*100) + '%"';
						});  				
						
						//document.write(data);
						
						
						var transform_aa = [           
						{"tag":"p", children:function(){return(json2html.transform(this.data, transform_bb));}}
						];
						
						var transform_bb= 
						{"tag":"p", children:[
						{"tag":"p", children:[											
						//{"tag": "li", "html":"<a href='http://www.treeid/code_${code}' >${code} ${name}&nbsp;&nbsp;开(收)盘金额：${kpje}&nbsp;&nbsp;抢筹幅度：${fd}&nbsp;&nbsp;抢筹委托金额：${wtje}&nbsp;&nbsp;抢筹成交金额：${cjje}</a>"}, 							
						{"tag":"li", children:function(){
						var ks = "";
						if(t == "0")
						{							
							ks = "开盘金额";
						}
						else
						{							
							ks = "收盘金额";
						}									
						return("<a href=http://www.treeid/code_" + 
						this.code + " id='gg' onclick='changeCss(this,this.id)'>" + 						
						this.code + "&nbsp;" + 
						this.name + "&nbsp;&nbsp;" + 
						ks + "：" + this.kpje + "&nbsp;&nbsp;" +
						"抢筹幅度：" + this.fd + "&nbsp;&nbsp;" +
						"抢筹委托金额：" + this.wtje + "&nbsp;&nbsp;<br>" + 
						"&nbsp;&nbsp;&nbsp;&nbsp;抢筹成交金额：" + this.cjje + "</br></a>");											
						}}]}]}; 
						
						html = json2html.transform(data, transform_aa);																		
					}
					else
					{
						html = "暂无数据"
					}
					var pxs = "";
					if(px == "1")
						{							
							pxs = "按抢筹委托金额排序";
						}
					if(px == "2")
						{							
							pxs = "按抢筹成交金额排序";
						}
					if(px == "3")
						{	
						if(t == "0")
							{							
								pxs = "按开盘金额排序";;
							}
						else if(t == "1")
							{							
								pxs = "按收盘金额排序";;
							}														
						}
					if(px == "4")
						{							
							pxs = "按抢筹幅度排序";
						}						
					if(t == "0")
						{							
							div1.innerHTML = div1.innerHTML + '<h4>早盘抢筹（' + pxs + '）</h4>';
						}
					else if(t == "1")
						{							
							div1.innerHTML = div1.innerHTML + '<h4>尾盘抢筹（' + pxs + '）</h4>';
						}							
					div1.innerHTML = div1.innerHTML + "<span id='gg'>" + html +"</span>";

					//高亮
					var content = document.getElementById("gg").innerHTML;					
					var reg = new RegExp("(" + gl + ")", "g");  
					var str = content;  
					var newstr = str.replace(reg, "<font color=#FF6633>$1</font>");
					document.getElementById("gg").innerHTML = newstr;
					
				}				
			}
			
			
		</script>
	</head>
	<body>
		<div id="towrite" class="fixedBox"></div>
	</body>
</html>